package com.example.democonsumer.controller;

import com.example.api.Order;
import com.example.api.SexType;
import com.example.api.UserProvider;
import com.example.democonsumer.service.OpenFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <b><code>OpenFeignController</code></b>
 * <p>
 * Description
 * <p>
 * <b>Create Time:</b> 2021/9/24 11:15.
 *
 * @author qd.yt
 * @version 0.0.1
 * @since demo-openfeign v0.0.1
 */
@RestController
@RequestMapping("/openfeign")
public class OpenFeignController {
    @Autowired
    OpenFeignService openfeignService;

    @Resource
    UserProvider userProvider;

    @RequestMapping("/get")
    public String get(){
        return openfeignService.get(1);
    }

    @RequestMapping("/user2")
    public String userU2(){
        return userProvider.getUser2(1,"xx","88");
    }

    @RequestMapping("/user1")
    public String getU(){
        return userProvider.getUser(1,null);
    }


    @RequestMapping("/user")
    public String user(){
        return userProvider.getUser(1);
    }

    @RequestMapping("/order")
    public String order(){
        Order order = new Order();
        order.setId("1");
        order.setName("xixi");
        return userProvider.saveOrder(order);
    }

    @RequestMapping("/updateOrder")
    public String updateOrder(){
        Order order = new Order();
        order.setId("1");
        order.setName("xixi");
        return userProvider.updateOrder(order,"1");
    }

    @RequestMapping("/sendMap")
    public String sendMap(){
        HashMap<String,Object> temp = new HashMap<>();
        Order order = new Order();
        order.setName("order");
        order.setId("1");
        temp.put("abc",order);
        return userProvider.sendMap(temp);
    }

    @RequestMapping("/sendList")
    public String sendList(){
        List<Order> temp = new ArrayList<>();
        Order order = new Order();
        order.setName("order");
        order.setId("1");
        temp.add(order);
        return userProvider.sendList("1",temp);
    }

    @RequestMapping("/sendMore")
    public String sendMore(){
        List<Order> temp = new ArrayList<>();
        Order order = new Order();
        order.setName("order");
        order.setId("1");
        temp.add(order);
        return userProvider.sendListMore("1","2",temp,order);
    }

    @RequestMapping("/sendListMap")
    public String sendListMap(){
        HashMap<String,Object> temp1 = new HashMap<>();
        Order order = new Order();
        order.setName("order");
        order.setId("1");
        temp1.put("abc",order);

        List<Order> temp = new ArrayList<>();
        Order order1 = new Order();
        order1.setName("order");
        order1.setId("1");
        temp.add(order1);
        return userProvider.sendListMap(temp1,temp);
    }

    @RequestMapping("/sendEnumList")
    public String sendEnumList(){
        SexType sexType  = SexType.BODY;
        List<String> temp = new ArrayList<>();
        temp.add("a");
        temp.add("b");
        return userProvider.sendEnumList(sexType,"1",temp);
    }

}
